import dxRequest from "../../../../network/index"
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    bookInfo: {
      type: Object,
      value: []
    },
    isUseBookStatus: {
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    jumpToDetail(e) {
      wx.navigateTo({
        url: '/pages/bookDetail/bookDetail?bookInfo=' + JSON.stringify(e.currentTarget.dataset.bookinfo)
      })
    },
    handleReturn(e) {
      // console.log(e.currentTarget.dataset);
      const _this = this
      wx.showModal({
        title: '提示',
        content: '确定归还',
        success(res) {
          if (res.confirm) {
            // console.log('用户点击确定')
            dxRequest("delete", '/borrow/deleteBook', {
              user_id: getApp().globalData.userInfo.openid,
              book_id: e.currentTarget.dataset.bookid,
              status: 4
            })
              .then(res => {
                console.log(res);
                wx.showToast({
                  title: '归还成功',
                })
                wx.reLaunch({
                  url: '/pages/borrow/borrow'
                })
              })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    },
    handleCancel(e) {
      console.log(e.currentTarget.dataset);
      const _this = this
      wx.showModal({
        title: '提示',
        content: '确定取消预约',
        success(res) {
          if (res.confirm) {
            // console.log('用户点击确定')
            dxRequest("delete", '/borrow/cancelSubscribe', {
              user_id: getApp().globalData.userInfo.openid,
              book_id: e.currentTarget.dataset.bookid
            })
              .then(res => {
                console.log(res);
                wx.showToast({
                  title: '取消成功',
                })
                wx.reLaunch({
                  url: '/pages/borrow/borrow'
                })
              })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })

    }
  }
})